
#pragma once

#include "parser.h"
#include "device.h"

#include <map>

namespace serial {

class SerialDevice : public Device, Parser {
public:
    SerialDevice(const char * node);
    ~SerialDevice();

    class Listener {
    public:
        Listener() {}
        virtual ~Listener() {}
        virtual void onCommand(unsigned char * command, int len) = 0;
    };

    void registerFsmListener(Parser::FSM* fsm, Listener* listener);

    // override from Device::onRead();
    virtual void onRead(const char * buf, int len);
private:
    SerialDevice();
    std::map<const Parser::FSM*, Listener*>   mListeners;
};

} // namespace serial

